package com.ruoyi.eamp.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.eamp.domain.EampCarList;
import com.ruoyi.eamp.domain.EampCarLogs;
import com.ruoyi.eamp.domain.EampCarUse;
import com.ruoyi.eamp.domain.vo.EampListAndEampUse;
import com.ruoyi.eamp.mapper.EampCarListMapper;
import com.ruoyi.eamp.mapper.EampCarLogsMapper;
import com.ruoyi.eamp.mapper.EampCarUseMapper;
import com.ruoyi.eamp.service.IEampCarUseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 车辆使用表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-08
 */
@Service
public class EampCarUseServiceImpl implements IEampCarUseService 
{
    @Autowired
    private EampCarUseMapper eampCarUseMapper;

    @Autowired
    private EampCarListMapper eampCarListMapper;

    @Autowired
    private EampCarLogsMapper eampCarLogsMapper;

    /**
     * 查询车辆使用表
     * 
     * @param useId 车辆使用表主键
     * @return 车辆使用表
     */
    @Override
    public EampCarUse selectEampCarUseByUseId(Long useId)
    {
        return eampCarUseMapper.selectEampCarUseByUseId(useId);
    }

    @Override
    public List<EampCarUse> selectEampCarUseList(EampCarUse eampCarUse) {


        return eampCarUseMapper.selectEampCarList(eampCarUse);
    }

    /**
     * 查询车辆使用表列表
     * 
     * @param eampListAndEampUse 车辆使用表
     * @return 车辆使用表
     */
    @Override
    public List<EampListAndEampUse> selectEampCarUseList(EampListAndEampUse eampListAndEampUse)
    {
        return eampCarUseMapper.selectEampCarUseList(eampListAndEampUse);
    }

    /**
     * 新增车辆使用表
     * 
     * @param eampCarUse 车辆使用表
     * @return 结果
     */
    @Override
    public int insertEampCarUse(EampCarUse eampCarUse)
    {
        System.out.println(eampCarUse);
        EampCarList eampCarList=new EampCarList();
        eampCarList.setCarId(eampCarUse.getCarId());
        eampCarList.setCarState(2L);
        eampCarListMapper.updateEampCarList(eampCarList);
        return eampCarUseMapper.insertEampCarUse(eampCarUse);
    }

    /**
     * 修改车辆使用表
     * 
     * @param eampCarUse 车辆使用表
     * @return 结果
     */
    @Override
    public int updateEampCarUse(EampCarUse eampCarUse)
    {
        EampCarList eampCarList = new EampCarList();
        eampCarList.setCarState(0l);
        eampCarList.setCarId(eampCarUse.getCarId());
        eampCarListMapper.updateEampCarList(eampCarList);
        Long userId = SecurityUtils.getUserId();
        Long carId = eampCarUse.getCarId();
        Date date = new Date();
        EampCarLogs eampCarLogs = new EampCarLogs(null,1L,1l,carId,userId,date,null,null,2L);
        eampCarLogsMapper.insertEampCarLogs(eampCarLogs);
        int i = eampCarUseMapper.updateEampCarUse(eampCarUse);
        return i;

    }

    /**
     * 批量删除车辆使用表
     * 
     * @param useIds 需要删除的车辆使用表主键
     * @return 结果
     */
    @Override
    public int deleteEampCarUseByUseIds(Long[] useIds)
    {
        return eampCarUseMapper.deleteEampCarUseByUseIds(useIds);
    }

    /**
     * 删除车辆使用表信息
     * 
     * @param useId 车辆使用表主键
     * @return 结果
     */
    @Override
    public int deleteEampCarUseByUseId(Long useId)
    {
        EampCarList eampCarList = new EampCarList();
        return eampCarUseMapper.deleteEampCarUseByUseId(useId);
    }
}
